package ch.be.coop.unterhaltLaden.presentation.framesPanels;

import java.awt.BorderLayout;
import java.awt.ScrollPane;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;

import ch.be.coop.unterhaltLaden.busines.CoopStore;
import ch.be.coop.unterhaltLaden.busines.Engine;

public class ListPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Engine engine;
	private JList list;
	private DefaultListModel listModel;
	private ScrollPane scrollPane;

	public ListPanel(Engine engine) {
		
		this.setName("Liste von Coop");
		
		this.engine = engine;

		this.list = new JList();
		this.listModel = new DefaultListModel();
		list.setModel(listModel);
		this.setLayout(new BorderLayout());
		
		filllist();


		scrollPane = new ScrollPane();
		
		scrollPane.add(list);
		this.add(scrollPane);
		
	}

	
	public JList getList() {
		return list;
	}


	public DefaultListModel getListModel() {
		return listModel;
	}


	private void filllist() {
		
		for (CoopStore coop : engine.getCoopList()) {
			this.listModel.addElement(coop.getName());
		}
		
	}

}
